﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NSsh.Common.Types;
using NUnit.Framework.SyntaxHelpers;
using System.IO;
using System.Collections;

namespace NSsh.Common.Tests.Types
{
    [TestFixture]
    public class SshByteArrayFixture
    {
        [Test]
        public void ShouldCreateFromString()
        {
            byte[] value = { 0x1, 0x2 };
            SshByteArray sshByteArray = new SshByteArray(value);

            Assert.That(sshByteArray.Value, Is.EqualTo(value), "Value incorrect.");
        }

        [Test]
        public void ShouldCreateFromNullArray()
        {
            MemoryStream memoryStream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(memoryStream);
            writer.Write((uint)0);

            SshByteArray sshByteArray = new SshByteArray((byte[])null);

            Assert.That(sshByteArray.Value, Is.EqualTo(null), "Value incorrect.");
            Assert.That(sshByteArray.ToByteArray(), Is.EqualTo(memoryStream.ToArray()), "ToByteArray result wrong.");
        }

        [Test]
        public void ShouldCreateFromBinaryReader()
        {
            string value = "value";

            MemoryStream memoryStream = new MemoryStream();

            BinaryWriter writer = new BinaryWriter(memoryStream);
            writer.WriteBE((uint)5);
            writer.Write(Encoding.UTF8.GetBytes(value));

            memoryStream.Seek(0, SeekOrigin.Begin);

            BinaryReader reader = new BinaryReader(memoryStream);

            SshByteArray sshByteArray = new SshByteArray(reader);

            Assert.That(Encoding.UTF8.GetString(sshByteArray.Value), Is.EqualTo(value), "Value incorrect.");
            Assert.That(sshByteArray.ToByteArray(), Is.EqualTo(memoryStream.ToArray()), "ToByteArray result wrong.");
        }
    }
}
